import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import { mars3dPlugin } from 'vite-plugin-mars3d';
import postCssPxToRem from 'postcss-pxtorem'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools({
      // launchEditor: 'Cursor',
      launchEditor: 'C:\\Program Files\\JetBrains\\WebStorm 2025.1.3\\bin\\webstorm64.exe',
    }),
    mars3dPlugin(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/styles/variables.scss" as *;`,
      },
    },
    postcss:{
      plugins: [
        {
          postcssPlugin: 'internal:charset-removal',
          AtRule: {
            charset: (atRule) => {
              if (atRule.name === 'charset') {
                atRule.remove();
              }
            }
          }
        },
        postCssPxToRem({
          rootValue: 192,
          propList: ['*'],
          selectorBlackList: ['.norem'],
          exclude: /node_modules/i,
          minPixelValue: 1,
          mediaQuery: false,
          unitPrecision: 5,
          replace: true,
        })
      ]
    }
  },
  server: {
    host: true,
    open: true,
    proxy: {
      '/dev-api': {
        target: 'http://192.168.1.26:9003',
        // target: 'http://192.168.0.100:9003',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, ''),
      },
      '/geoserver': {
        target: 'http://192.168.1.26:9001',
        // target: 'http://192.168.0.100:9001',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, ''),
      },
    },
  },
})
